﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.BusinessLogic.Interfaces;
using KCMS.BusinessLogic.Models;
using StructureMap;

namespace KCMS.BusinessLogic.Engine
{
    public class Calculator:ICalculator
    {
        private ICartService cartService = ObjectFactory.GetInstance<ICartService>();

        public double getTotal(IEnumerable<CartItem> items)
        {
            try
            {
                double total = 0;
                items = cartService.BuildFullModel(items);

                foreach (CartItem item in items)
                {
                    //item = cartService.BuildFullModel(item);
                    total = total + item.Product.Price * item.quantity;
                }
                return total;
            }
            catch
            {
                return 0;
            }
            
        }


        public double getTotal(IEnumerable<OrderItem> items)
        {
            try
            {
                double total = 0;

                foreach (OrderItem item in items)
                {
                    total = total + item.Product.Price * item.Quantity;
                }
                return total;
            }
            catch
            {
                return 0;
            }
        }
    }
}
